package gui;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;

public class RegexenDialog extends JFrame implements ActionListener {

    private JPanel testPanel = new JPanel();
    protected Vector<String> text = new Vector<String>();
    private Vector<JTextField> boxes = new Vector<JTextField>();

    public RegexenDialog(int nBoxes) {
        text.ensureCapacity(nBoxes);
        boxes.ensureCapacity(nBoxes);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(350, nBoxes * 35);
        setTitle("Regexen");
        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
        JButton ok = new JButton("OK");
        ok.addActionListener(new TestListener());

        getContentPane().add(testPanel);
        getContentPane().add(ok);

        for (int i = nBoxes; i > 0; i--) {
            JTextField field = new JTextField(20);
            boxes.add(field);
            testPanel.add(field);
        }
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
    }

    class TestListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {

            text.clear();
            for (int i = 0; i < boxes.size(); i++) {
                text.add(boxes.elementAt(i).getText());
            }
            for (int i = 0; i < text.size(); i++) {
                System.out.println(text.elementAt(i));
            }

            testPanel.validate();

        }
    }
}
